import Vue from 'vue'
import Vuex from 'vuex'

import {Login} from '../http'

Vue.use(Vuex)
let state = JSON.parse(localStorage.getItem('userInfo')) || {}

export default new Vuex.Store({
  state,
  getters: {
    // 侧边栏的数据
  },
  mutations: {
    saveUserInfo(state, info) {
      state.userInfo = info;
      localStorage.setItem('userInfo', JSON.stringify(info))
    }
  },
  actions: {
    async getUserinfo({commit}, data){
      let res = await Login(data);
      console.log(res);
      commit('saveUserInfo', res.list)
    }
  },
  modules: {
  }
})
